package com.czk.netty.netty.inboundandoutboundhandler.server;

import com.czk.netty.netty.inboundandoutboundhandler.client.MyLongToByteEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/1/20 22:29
 */
public class MyServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        // 加入相关的handler
        //   pipeline.addLast(new MyByteToLongDecoder());
        //  加入netty提供的ReplayingDecoder 不要哦判断长度，内部会自行判断
        pipeline.addLast(new MyByteToLongDecode2());
        // 加入出站handler->发送数据给客户端
        pipeline.addLast(new MyLongToByteEncoder());
        pipeline.addLast(new MyServerHandler());
    }
}
